package code.google.jcontainer.invoke;

import java.lang.reflect.Method;

/**
 * The InvocationHandler to invoke method by reflect
 * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
 */
public class MethodInvocationHandler implements InvocationHandler {

    public void chainInvoke(final Invocation invocation) throws Exception {
        // need to handle the registered Interceptors
        Object targetComponent = invocation.getTargetComponent();
        Method targetMethod = invocation.getTargetMethod();
        Object result = targetMethod.invoke(targetComponent, invocation.getParameters());
        invocation.setResult(result);
    }

    public void chainReturn(Invocation invocation) throws Exception {
        // do nothing
    }

    public void onCaughtException(Invocation invocation, Exception e) {
        invocation.onCaughtException(e);
    }
}
